package com.sly.demo.mapstruct.model.converter;

import com.sly.demo.mapstruct.model.dto.GoodsDto;
import com.sly.demo.mapstruct.model.po.Goods;
import com.sly.demo.mapstruct.model.vo.GoodsVo;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import org.mapstruct.ReportingPolicy;
import org.mapstruct.factory.Mappers;

import java.util.List;

/**
 * 商品转换器
 *
 * @author SLY
 * @date 2022/8/7
 */
@Mapper(unmappedSourcePolicy = ReportingPolicy.WARN, unmappedTargetPolicy = ReportingPolicy.WARN)
public interface GoodsConverter {

    GoodsConverter INSTANCE = Mappers.getMapper(GoodsConverter.class);

    /**
     * 商品实体转商品Dto
     *
     * @param goods 商品实体
     * @return {@link GoodsDto}
     */
    GoodsDto goodsToGoodsDto(Goods goods);

    /**
     * 商品实体转商品Dto列表
     *
     * @param goodsList 商品实体列表
     * @return {@link List}<{@link GoodsDto}>
     */
    List<GoodsDto> goodsToGoodsDtoList(List<Goods> goodsList);

    /**
     * 商品Dto转商品Vo
     *
     * @param goodsDto 商品Dto
     * @return {@link GoodsVo}
     */
    @Mappings({
            @Mapping(expression = "java(CommonExpression.parseStatusToStatusStr(goodsDto.getStatus()))", target = "status"),
    })
    GoodsVo goodsDtoToGoodsVo(GoodsDto goodsDto);

    /**
     * 商品Dto转商品Vo列表
     *
     * @param goodsList 商品Dto列表
     * @return {@link List}<{@link GoodsVo}>
     */
    List<GoodsVo> goodsDtoToGoodsVoList(List<GoodsDto> goodsList);
}
